<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>CRM后台管理系统登录</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <!--引入本地的css样式-->
  <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="static/css/admin.css" media="all">
  <link rel="stylesheet" href="static/css/login.css" media="all">

</head>
<body style="background-color: #009688;">

  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main" style="background-color: white;">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>CRM后台管理系统</h2>
        <p>百杰297官方出品的后台管理系统</p>
      </div>
      <form class="layadmin-user-login-box layadmin-user-login-body layui-form" action="" style="padding: 20px;">
           <!--用户名-->
          <div class="layui-form-item">
            <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
            <input type="text" name="username" id="LAY-user-login-username" lay-verify="required|username" placeholder="用户名" class="layui-input">
          </div>
          <div class="layui-form-item">
            <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
            <input type="password" name="password" id="LAY-user-login-password" lay-verify="required|password" placeholder="密码" class="layui-input">
          </div>
          <!--验证码-->
          <div class="layui-form-item">
          <div class="layui-row">
            <div class="layui-col-xs7">
              <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
              <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required|vercode" placeholder="图形验证码" class="layui-input">
            </div>
            <!--生成图片验证码-->
            <div class="layui-col-xs5">
              <div style="margin-left: 10px;">
                <img class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
              </div>
            </div>
          </div>
        </div>
          <div class="layui-form-item" style="margin-bottom: 20px;">
          <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
          <a href="forget.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
        </div>
          <!--提交-->
          <div class="layui-form-item">
              <button type="submit" class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="demo1">立即提交</button>
          </div>
      </form>
    </div>

    <!--页尾-->
    <div class="layui-trans layadmin-user-login-footer">
      <p>© 2021 <a href="http://www.layui.com/" target="_blank">www.bj273.com</a></p>
    </div>

    
  </div>


  <script src="static/js/jquery-3.6.0.min.js"></script>
  <!--引入本地layui.js-->
  <script src="static/layui/layui.js"></script>
  <script type="text/javascript">
         //验证码的获取
         // 获取验证码
         $.get('/captcha' ,function(res) {
             $('#LAY-user-get-vercode').attr('src', res.image);
         },'json');

         $("#LAY-user-get-vercode").click(function () {
             $.get('/captcha' ,function(res) {
                 $('#LAY-user-get-vercode').attr('src', res.image);
             },'json');
         })

  </script>
  <script type="text/javascript">
      layui.use(['form', 'layedit', 'laydate','layer'], function(){
          var form = layui.form
              ,layer = layui.layer
              ,layedit = layui.layedit
              ,laydate = layui.laydate;

          //自定义验证规则
          form.verify({
              username: function(value){
                  if(value.length < 3){
                      return '用户名称至少3字符啊';
                  }
              }
              ,password: [
                  /^[\S]{6,12}$/
                  ,'密码必须6到12位，且不能出现空格'
              ]
              ,vercode: function (value) {
                  if(value.length != 4){
                      return '验证码是4个字符啊';
                  }
              }
              ,content: function(value){
                  layedit.sync(editIndex);
              }
          });





          //监听提交
          form.on('submit(demo1)', function(data){
              $.ajax({
                   url:"/login",
                   type:"get",
                   data:data.field,
                   dataType:"json",
                   success: function(res){
                       if(res.code == 200){//登录成功，直接跳转到登录成功后的界面，并且将账户信息带入到主界面去
                           //登入成功的提示与跳转
                           layer.msg('登录成功', {
                               offset: '15px'
                               ,icon: 1
                               ,time: 1000
                           }, function(){
                               var user = res.data;
                               //将登录成功后对象转换成JSON字符串存储到sessionStorage对象中
                               sessionStorage.setItem("user",JSON.stringify(user));
                               //做跳转，而且还得把user对象带入到成功界面
                               window.location.href = "views/index.html";
                           });
                       }
                       if(res.code == 401){//验证码错误
                           alert(res.msg);
                       }
                       if(res.code == 500){//用户名称或密码有误，登录失败
                           alert(res.msg);
                       }
                       if(res.code == 501){//系统开小差了，请联系管理员
                           alert(res.msg);
                       }
                   }
              })
              return false;
          });





      });
  </script>


</body>
</html>